package com.syyo.admin.controller;


import com.syyo.admin.domain.ResultVo;
import com.syyo.admin.domain.req.RoleReq;
import com.syyo.admin.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wang
 * @since 2020-07-17
 */
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private SysRoleService roleService;

    /**
     * 角色新增
     * @param req
     * @return
     */
    @PreAuthorize("@el.check('system:role:add')")
    @PostMapping
    public ResultVo add(@RequestBody RoleReq req){
        return roleService.add(req);
    }

    /**
     * 角色删除
     * @param req
     * @return
     */
    @PreAuthorize("@el.check('system:role:del')")
    @DeleteMapping
    public ResultVo del(@RequestBody RoleReq req){
        return roleService.del(req);
    }

    /**
     * 角色修改
     * @param req
     * @return
     */
    @PreAuthorize("@el.check('system:role:edit')")
    @PutMapping
    public ResultVo edit(@RequestBody RoleReq req){
        return roleService.edit(req);
    }


    /**
     * 角色详情
     * @param
     * @return
     */
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id")Integer id){
        return roleService.findOne(id);
    }

    /**
     * 角色列表
     * @param req
     * @return
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findAll(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            RoleReq req){
        return roleService.findAll(pageNum,pageSize,req);
    }

    /**
     * 角色分配权限
     * @param req
     * @return
     */
    @PreAuthorize("@el.check('system:role:auth')")
    @PutMapping("/auth")
    public ResultVo auth(@RequestBody RoleReq req){
        return roleService.auth(req);
    }
}
